package net.qiqbframework.messaging.task;

public enum TaskPhase {
    /**
     * 未开始阶段，任务创建期
     */
    NOT_STARTED(false, false, false),

    /**
     * 调用 start 方法后
     */
    STARTED(true, false, false),

    /**
     * 规划阶段
     */
    PLAN(true, false, false),

    PREPARE_COMMIT(true, false, false),


    COMMIT(true, true, false),


    ROLLBACK(true, true, true),


    AFTER_COMMIT(true, true, true),


    CLEANUP(false, true, true),


    CLOSED(false, true, true);

    private final boolean started;
    private final boolean reverseCallbackOrder;
    private final boolean suppressHandlerErrors;

    TaskPhase(boolean started, boolean reverseCallbackOrder, boolean suppressHandlerErrors) {
        this.started = started;
        this.reverseCallbackOrder = reverseCallbackOrder;
        this.suppressHandlerErrors = suppressHandlerErrors;
    }

    public boolean isStarted() {
        return started;
    }


    public boolean isReverseCallbackOrder() {
        return reverseCallbackOrder;
    }


    public boolean isSuppressHandlerErrors() {
        return suppressHandlerErrors;
    }


    public boolean isBefore( TaskPhase phase) {
        return ordinal() < phase.ordinal();
    }

    public boolean isAfter( TaskPhase phase) {
        return ordinal() > phase.ordinal();
    }
}
